package cn.qidd.keep.manage.model.system;

import cn.qidd.keep.domain.core.dict.SuccessOrFailure;
import cn.qidd.keep.domain.document.QOperationLog;
import cn.qidd.keep.domain.model.BaseSearch;
import com.querydsl.core.BooleanBuilder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * Created by sunyanping on 2019/3/5
 */
@Data
public class OperationLogParams extends BaseSearch {

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date operatorTimeMin;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date operatorTimeMax;

    private String operatorName;
    private String operatorRealName;
    private SuccessOrFailure status;

    @Override
    public BooleanBuilder generateSearchCondition() {
        BooleanBuilder builder = new BooleanBuilder();
        QOperationLog qMongoOperationLog = QOperationLog.operationLog;
        if (this.operatorTimeMin != null) {
            builder.and(qMongoOperationLog.operatorTime.after(this.operatorTimeMin));
        }
        if (this.operatorTimeMax != null) {
            builder.and(qMongoOperationLog.operatorTime.before(this.operatorTimeMax));
        }
        if (StringUtils.isNotBlank(this.operatorName)) {
            builder.and(qMongoOperationLog.operatorName.eq(this.operatorName.trim()));
        }
        if (StringUtils.isNotBlank(this.operatorRealName)) {
            builder.and(qMongoOperationLog.operatorRealName.eq(this.operatorRealName.trim()));
        }
        if (status != null) {
            builder.and(qMongoOperationLog.status.eq(this.status));
        }
        return builder;
    }
}
